package DianShang_2024.ds_02.extract

import org.apache.spark.sql.SparkSession

object table_preparation {
  def main(args: Array[String]): Unit = {
          //  准备spark集成hudi的环境
    val spark=SparkSession.builder()
      .master("local[*]")
      .appName("数据抽取的表格准备")
      .config("spark.serializer","org.apache.spark.serializer.KryoSerializer")
      .config("spark.sql.extensions","org.apache.spark.sql.hudi.HoodieSparkSessionExtension")
      .enableHiveSupport()
      .getOrCreate()

    spark.sql("use ods_ds_hudi02")

    //  user_info
    spark.sql("drop table if exists user_info")
    spark.sql(
      """
        |create table if not exists user_info(
        |id int,
        |login_name String,
        |nick_name String,
        |passwd String,
        |name String,
        |phone_num String,
        |email String,
        |head_img String,
        |user_level String,
        |birthday String,
        |gender String,
        |create_time String,
        |operate_time String
        |)using hudi
        |tblproperties(
        |type="cow",
        |primaryKey="id",
        |preCombineField="operate_time",
        |hoodie.datasource.hive_aync.mode="hms"
        |)
        |partitioned by(etl_date String)
        |""".stripMargin)

     // sku_info
    spark.sql("drop table if exists sku_info")
    spark.sql(
      """
        |create table if not exists sku_info(
        |id int,
        |spu_id int,
        |price decimal(10,0),
        |sku_name String,
        |sku_desc String,
        |weight decimal(10,2),
        |tm_id int,
        |category3_id int,
        |sku_default_img String,
        |create_time String
        |)using hudi
        |tblproperties(
        |type="cow",
        |primaryKey="id",
        |preCombineField="create_time",
        |hoodie.datasource.hive_aync.mode="hms"
        |)
        |partitioned by(etl_date String)
        |""".stripMargin)
//
//    //  base_province
//    spark.sql("drop table if exists base_province")
//    spark.sql(
//      """
//        |create table if not exists base_province(
//        |id int,
//        |name  String,
//        |region_id String,
//        |area_code String,
//        |iso_code String,
//        |create_time  String
//        |)using hudi
//        |tblproperties(
//        |type="cow",
//        |primaryKey="id",
//        |preCombineField="create_time",
//        |hoodie.datasource.hive_aync.mode="hms"
//        |)
//        |partitioned by(etl_date String)
//        |""".stripMargin)
//
//    //  base_region
//    spark.sql("drop table if exists base_region")
//    spark.sql(
//      """
//        |create table if not exists base_region(
//        |id int,
//        |region_name String,
//        |create_time String
//        |)using hudi
//        |tblproperties(
//        |type="cow",
//        |primaryKey="id",
//        |preCombineField="create_time",
//        |hoodie.datasource.hive_aync.mode="hms"
//        |)
//        |partitioned by(etl_date String)
//        |""".stripMargin)
//
//    //  order_info
//    spark.sql("drop table if exists order_info")
//    spark.sql(
//      """
//        |create table if not exists order_info(
//        |id int,
//        |consignee String,
//        |consignee_tel String,
//        |final_total_amount decimal(16,2),
//        |order_status String,
//        |user_id int,
//        |delivery_address String,
//        |order_comment String,
//        |out_trade_no String,
//        |trade_body String,
//        |create_time String,
//        |operate_time String,
//        |expire_time String,
//        |tracking_no String,
//        |parent_order_id int,
//        |img_url String,
//        |province_id int,
//        |benefit_reduce_amount decimal(16,2),
//        |original_total_amount decimal(16,2),
//        |feight_fee decimal(16,2)
//        |)using hudi
//        |tblproperties(
//        |type="cow",
//        |primaryKey="id",
//        |preCombineField="operate_time",
//        |hoodie.datasource.hive_aync.mode="hms"
//        |)
//        |partitioned by(etl_date String)
//        |""".stripMargin)
////
//    //  order_detail
//    spark.sql("drop table if exists order_detail")
//    spark.sql(
//      """
//        |create table if not exists order_detail(
//        |id int,
//        |order_id int,
//        |sku_id int,
//        |sku_name String,
//        |img_url String,
//        |order_price decimal(10,2),
//        |sku_num String,
//        |create_time String,
//        |source_type String,
//        |source_id int
//        |)using hudi
//        |tblproperties(
//        |type="cow",
//        |primaryKey="id",
//        |preCombineField="create_time",
//        |hoodie.datasource.hive_aync.mode="hms"
//        |)
//        |partitioned by(etl_date String)
//        |""".stripMargin)

    //  查看表
    spark.sql("show tables").show


    //  关闭spark的环境
    spark.close()






  }

}
